package com.baili.service.admin;
 
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.baili.dao.admin.AdminDao;
import com.baili.dto.Defect;
import com.baili.dto.SelectUserInput;
import com.baili.util.EhcacheUtil;
import com.baili.util.StringUtil;

/** 
 * @author iceX
 * @version 创建时间：2016年3月25日 上午10:04:45 
 * @Name: CallServiceImpl.java
 */ 
@Service
public class AdminServiceImpl implements AdminService{

	@Autowired
	private AdminDao adminDao;
	@Autowired
	private EhcacheUtil ehcacheUtil;

	@Override
	public List adminApCount() {
		
		return adminDao.adminApCount();
	}

	@Override
	public List adminApList(int approve) {
		
		return adminDao.adminApList(approve);
	}

	@Override
	public List adminApById(int id) {
		
		return adminDao.adminApById(id);
	}

	@Override
	public void updateApState(SelectUserInput user) {
		
		adminDao.updateApState(user);
	}

	@Override
	public List getAdminName(SelectUserInput user) {
		
		return adminDao.getAdminName(user);
	}

	@Override
	public List adminApByRoleName(SelectUserInput user) {
		
		return adminDao.adminApByRoleName(user);
	}
	@Override
	public List getProcess() {
		
		return adminDao.getProcess();
	}
	@Override
	public List getProcessById(int id) {
		
		return adminDao.getProcessById(id);
	}
	@Override
	public void uploadfile(CommonsMultipartFile picture) {
		
		adminDao.uploadfile(picture);
	}
	@Override
	public void uploadQualityCheck(Defect defect) {
		
		adminDao.uploadQualityCheck(defect);
	}

	@Override
	public String uploadfiles(String userid,String picVdoIds) throws Exception {
		
		String[] picVdoId = picVdoIds.split(",");
		
		String sysDate = StringUtil.genOrderNum();
		
		for(int i=0 ; i<picVdoId.length ; i++){
			
			Map<String,Object> map = (Map<String,Object>)ehcacheUtil.getCacheElement(userid);
			
			InputStream fil = (InputStream)map.get(picVdoId[i]);
			String type = map.get(picVdoId[i]+"type").toString();
			
			
			//CommonsMultipartFile file = (CommonsMultipartFile)ehcacheUtil.getCacheElement(userid);
			
			String filename =  sysDate +"_"+(i+1);// 取当前时间戳作为文件
			
			adminDao.uploadfiles(fil,filename,type);
			
		}
		
		return sysDate;
	}

	@Override
	public List getVersion() {
		
		return adminDao.getVersion();
	}
	@Override
	public void callSet(String callType,Integer processId,Integer charge) {
		
		adminDao.callSet(callType,processId,charge);
	}
	@Override
	public void insertSize(Integer size,Integer sex) {
		
		adminDao.insertSize(size,sex);
	}
	@Override
	public void deleteSize(Integer sizeId) {
		
		adminDao.deleteSize(sizeId);
	}
	@Override
	public void deleteDefectType(Integer defetcId) {
		
		adminDao.deleteDefectType(defetcId);
	}

	@Override
	public void defectSet(String defectName,Integer processId) {
		
		adminDao.defectSet(defectName,processId);
	}
}
